package org.kim.dao;

import org.kim.core.StorageCache;
import org.kim.exception.DAOException;
import org.kim.pojo.Account;


public class AccountDao extends BaseDao<Account>{

    public boolean accountExists(String accountId) {
        if (StorageCache.accountCache.get(accountId) != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean register(Account account) throws Exception {
        if (StorageCache.accountCache.get(account.getAccountId()) != null) {
           throw new DAOException("account exists");
        }
        StorageCache.accountCache.put(account.getAccountId(), account);
        super.persistence(account, "account-"+account.getAccountId());
        return true;
    }

    public Account search(String accountId) {
        Object obj= StorageCache.accountCache.get(accountId);
        if(obj!=null){
            return (Account) obj;
        }
        return null;
    }
}
